pageLoaded = 0;				// Prevent access to layers until they're loaded

delayedPreloadImages = new Array();
onloadFunctions = new Array();

// Set the pageLoaded variable to denote that the layers are ready to be used 
function doLoadProc() {
	pageLoaded = 1;
	
	for (i in delayedPreloadImages) {
		if (typeof delayedPreloadImages[i] != "function") {
			eval(i + " = preload('" + delayedPreloadImages[i] + "')");
		}
	}
	
	for (i in onloadFunctions) {
		if (i != "getIndex") {
			onloadFunctions[i]();
		}
	}
}

// swapImg - swaps an image for another that has already been preloaded.
function swapImg(imgName, preloadedImgName) {
	if (document[imgName]) {
		document[imgName].src = eval(preloadedImgName).src;
	}
}

function preload(imgSrc) {
	img = new Image();
	img.src = imgSrc;
	return img;
}

function delayedPreload(imgName, imgSrc) {
	if (!pageLoaded) {
		eval(imgName + " = new Image()");
		delayedPreloadImages[imgName] = imgSrc;
	} else {
		eval(imgName + " = preload('" + imgSrc + "')");
	}
}

function addOnLoad(func) {
	onloadFunctions[onloadFunctions.length] = func;
}

